package toubiao.domain.po.business;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

@Entity
@Table(name = "contact")
public class PoContact {
	
	private Long id;
	
	private String name;
	
	private String phone;
	
	private PoPartA partA;
	
	private Set<PoProject> projectSet=new HashSet<>();
	
	private Set<PoContract> contractSet=new HashSet<>();
	
	
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "ID")
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "partA_id")
	public PoPartA getPartA() {
		return partA;
	}

	public void setPartA(PoPartA partA) {
		this.partA = partA;
	}

	
	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "project_contact", joinColumns = { @JoinColumn(name = "contact_id", nullable = false) }, inverseJoinColumns = { @JoinColumn(name = "project_id", nullable = false) })
	@OrderBy("name ASC")
	public Set<PoProject> getProjectSet() {
		return projectSet;
	}

	public void setProjectSet(Set<PoProject> projectSet) {
		this.projectSet = projectSet;
	}
	
	
	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "contract_contact", joinColumns = { @JoinColumn(name = "contact_id", nullable = false) }, inverseJoinColumns = { @JoinColumn(name = "contract_id", nullable = false) })
	public Set<PoContract> getContractSet() {
		return contractSet;
	}

	public void setContractSet(Set<PoContract> contractSet) {
		this.contractSet = contractSet;
	}
	
}
